<%@ page import="com.cat.pojo.Student" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.mysql.cj.log.NullLogger" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Misterchaos
  Date: 2019/3/24
  Time: 6:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%
    request.setCharacterEncoding("utf-8");
    Student stu = null;
    String studentId = null;
    String studentName = null;
    String phoneNumber = null;
    String password = null;
    String userType = null;
    String portrait = null;
    String gender = null;
    String major = null;
    String majorClass = null;
    String position = null;
    String introduction = null;
    List<Student> list = (List<Student>) request.getAttribute("studentMap");
%>
<head>
    <title>管理员中心</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet"
          href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="jumbotron">
        <h1 align="center">管理员中心</h1>
        <p><strong>欢迎进入管理员中心
        </strong></p>
        <a href="StudentServlet?method=index" align="center" methods="post">
            <button type="button" class="btn btn-primary">返回主页</button>
        </a>
    </div>
</div>
<form action="AdminServlet" class="container">
    <input type="text" class="form-control"  name="value" style="width: 500px">
    <input type="submit" name="method" value="搜索">
    <input type="radio" name="attr" value="studentId" class="check-box" checked="checked">按学号搜索
    <input type="radio" name="attr" value="studentName" class="check-box">按姓名搜索
    <input type="radio" name="attr" value="position">按方向搜索
    <input type="radio" name="attr" value="gender">按性别搜索
    <input type="radio" name="attr" value="major">按专业搜索
</form>
<div class="table-responsive" align="center" style="padding: 40px">
    <%--定义变量--%>
    <%

    %>
    <%--输出表头--%>
    <%
        out.print("<table class=\"table table-striped\" border=\"0\">\n" +
                "    <caption align=\"left\">" + "所有学生" + "的报名表</caption>\n" +
                " <tr>\n" + " <th align=\"left\">学号</th>\n" +
                " <th align=\"left\">姓名</th>\n" +
                " <th align=\"left\">手机号</th>\n" +
                " <th align=\"left\">密码</th>\n" +
                " <th align=\"left\">用户类型</th>\n" +
                " <th align=\"left\">性别</th>\n" +
                " <th align=\"left\">专业</th>\n" +
                " <th align=\"left\">班级</th>\n" +
                " <th align=\"left\">方向</th>\n" +
                " <th align=\"left\">自我介绍</th>\n" +
                "<th align=\"left\">操作</th>\n" +
                "<th align=\"left\">操作</th>\n" +
                " </tr>\n"
        );
    %>
    <%-- 输出学生信息--%>
    <%
        //读取所有学生
        for (int i = 0; i < list.size(); i++) {
            //读取一个学生的信息
            stu = list.get(i);
            studentId = stu.getStudentId();
            studentName = stu.getStudentName();
            phoneNumber = stu.getPhoneNumber();
            password = stu.getPassword();
            userType = stu.getUserType();
            portrait = stu.getPortrait();
            gender = stu.getGender();
            major = stu.getMajor();
            majorClass = stu.getMajorClass();
            position = stu.getPosition();
            introduction = stu.getIntroduction();
            //把一个学生的信息输出到表格
            if (request.getParameter("update") != null && studentId.equalsIgnoreCase(request.getParameter("stuId"))) {
                out.print("<form action=\"AdminServlet\"method=\"post\">\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"studentId\" readonly=\"readonly\" value=\"" + studentId + "\" style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"studentName\" value=\"" + studentName + "\"         style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"phoneNumber\" value=\"" + phoneNumber + "\"         style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"password\" value=\"" + password + "\"         style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"userType\" value=\"" + userType + "\"         style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"gender\" value=\"" + gender + "\"         style=\"width:50px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"major\" value=\"" + major + "\"         style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"majorClass\" value=\"" + majorClass + "\" style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"position\" value=\"" + position + "\" style=\"width:100px\"/>\n" +
                        "    <td align=\"left\"><input type=\"text\" name=\"introduction\" value=\"" + introduction + "\"  style=\"width:300px\"/>\n" +
                        "    <td align=\"left\"><input type=\"submit\" name=\"method\" class=\"form-control\" value=\"修改\" style=\"width:50px\">\n" +
                        "    <td align=\"left\"><input type=\"submit\" name=\"method\" class=\"form-control\" value=\"取消\" style=\"width:50px\">\n" +
                        "</form>");
            } else {
                out.print(" <tr>\n" + " <td align=\"left\" name=\"delete\" value=\"" + studentId + "\">" + studentId + "</td>\n" +
                        " <td align=\"left\">" + studentName + "</td>\n" +
                        " <td align=\"left\" >" + phoneNumber + "</td>\n" +
                        " <td align=\"left\">" + "****" + "</td>\n" +
                        " <td align=\"left\">" + userType + "</td>\n" +
                        " <td align=\"left\">" + gender + "</td>\n" +
                        " <td align=\"left\">" + major + "</td>\n" +
                        " <td align=\"left\">" + majorClass + "</td>\n" +
                        " <td align=\"left\">" + position + "</td>\n" +
                        " <td align=\"left\">" + introduction + "</td>\n" +
                        "<td align=\"left\">" + "<form action=\"AdminServlet?method=update&stuId=" + studentId + "\"" +
                        " method=\"post\"><input type=\"submit\" class=\"form-control\" " + "value=\"修改\"></form></td>\n" +
                        "<td align=\"left\">" + "<form action=\"AdminServlet?method=delete&stuId=" + studentId + "\"" +
                        " method=\"post\"><input type=\"submit\" class=\"form-control\" " + "value=\"删除\"></form></td>\n" +
                        " </tr>\n" + "\n");
            }
        }
    %>
</div>
</body>
</html>
